// pages/pintuans/pintuans.js
var commonapi = require('../../component/service/commonapi.js');
var pintuanapi = require('../../component/service/pintuanapi.js');
var countDownT = require('../../component/countDown/countDownT.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    advs:[],
    inProcess:[],
    newList:[]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    //拼团广告图
    commonapi.getAdvs(11,function(res){
      that.setData({
        advs:res
      })
    });
    wx.setNavigationBarTitle({
      title: '精选拼团'
    })

    //拼团正在进行列表 查询最多10条记录
    pintuanapi.inProcessList(0,10,function(res){
      for (let i = 0; i < res.length; i++) {
        let countDown = new countDownT();        
        countDown.setExpireTime(res[i].serverTime,res[i].expireTime,"inProcess[" + i + "].countDownT",that);
        res[i].countDownT = countDown;
        res[i].percent = parseInt(res[i].actualQuantity*100/res[i].planQuantity);
      }
      that.setData({
        inProcess:res
      })
    });

    //拼团即将开始列表 查询最多10条记录
    pintuanapi.newList(0,10,function(res){
      for (let i = 0; i < res.length; i++) {
        let countDown = new countDownT();        
        countDown.setExpireTime(res[i].serverTime,res[i].expireTime,"newList[" + i + "].countDownT",that);
        res[i].countDownT = countDown;
        res[i].percent = parseInt(res[i].actualQuantity*100/res[i].planQuantity);
      }
      that.setData({
        newList:res
      })
    });
 
  },
    //拼团详情页
  getPintuanDetail:function(e){
    var itemId = e.currentTarget.dataset.itemId;
    wx.navigateTo({
      url: '../pintuan/pintuan?itemId=' + itemId,
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})